home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nfpat3.zip / MOUSE1.PRG < prev    next >
Text File  |  1992-11-29  |  46KB  |  1,563 lines

  1. /*
  2.  * File......: MOUSE1.PRG
  3.  * Author....: Leo Letendre
  4.  * CIS ID....: 73607,233
  5.  * Date......: $Date:   29 Nov 1992 22:17:06  $
  6.  * Revision..: $Revision:   1.10  $
  7.  * Log file..: $Logfile:   C:/nanfor/src/mouse1.prv  $
  8.  * 
  9.  * This is an original work by Robert DiFalco and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   C:/nanfor/src/mouse1.prv  $
  16.  * 
  17.  *    Rev 1.10   29 Nov 1992 22:17:06   GLENN
  18.  * Leo fixed a bug in ft_mreset() where it was always returning that a
  19.  * mouse was present.
  20.  * 
  21.  *    Rev 1.9   17 Oct 1992 16:28:58   GLENN
  22.  * Leo cleaned up documentation blocks.
  23.  * 
  24.  *    Rev 1.8   28 Sep 1992 01:38:14   GLENN
  25.  * Leo added FT_MGETSENS(), FT_MSETSENS(), FT_MSETPAGE(), FT_MGETPAGE(),
  26.  * and FT_MVERSION().
  27.  * 
  28.  * 
  29.  *    Rev 1.7   01 Jul 1992 01:45:18   GLENN
  30.  * Leo added documentation to FT_MDEFCRS and others. Added FT_MCONOFF(),
  31.  * FT_MINIT(), FT_MGETCOORD() and FT_MSETCOORD().  Restructured
  32.  * FT_MGETX() and FT_MGETY() for possible speed improvement and MAIN to
  33.  * better demonstrate some of the concerns when programming the mouse. 
  34.  * Added ability to change the number of rows and columns to demonstrate
  35.  * use in 43, 50 row mode etc. which is now supported in FT_MRESET() and
  36.  * FT_MINIT().
  37.  * 
  38.  *    Rev 1.6   23 Sep 1991 01:14:38   GLENN
  39.  * Corrected errors in syntax documention for FT_MBUTPRS() and FT_MDBLCLK(),
  40.  * found by Nantucket's Steve Silverwood.
  41.  * 
  42.  *    Rev 1.5   17 Aug 1991 15:34:52   GLENN
  43.  * Don Caton fixed some spelling errors in the doc
  44.  * 
  45.  *    Rev 1.4   15 Aug 1991 23:06:24   GLENN
  46.  * Forest Belt proofread/edited/cleaned up doc
  47.  * 
  48.  *    Rev 1.3   17 Jul 1991 22:28:40   GLENN
  49.  * Leo fixed a potential bug in ft_mcursor().
  50.  * 
  51.  *    Rev 1.2   27 May 1991 13:40:30   GLENN
  52.  * Leo Letendre sent me a revision of MOUSE1.PRG where he built in support
  53.  * for a three-button mouse, and revised the "double click" detection 
  54.  * algorithm.
  55.  *  
  56.  * Brought in compliance with new ft_int86().
  57.  * 
  58.  *    Rev 1.1   11 May 1991 00:16:48   GLENN
  59.  * ft_mgetpos() had a bug where the x and y coordinates were reversed. 
  60.  * Changed x coordinate to aRegs[3] and y coordinate to aRegs[4], just
  61.  * like in ft_msetpos().
  62.  * 
  63.  *    Rev 1.0   01 Apr 1991 01:01:48   GLENN
  64.  * Nanforum Toolkit
  65.  *
  66.  */
  67.  
  68.  
  69. // The original mouse routines were written by Robert diFalco but
  70. // Leo Letendre has made such major additions and modifications
  71. // and fixes that I've given him sole credit. -- G. Scott
  72.  
  73.  
  74. #include "FTINT86.CH"
  75.  
  76. static aReg[INT86_MAX_REGS]
  77. static lCrsState:=.F.
  78. static lMinit:=.F.
  79.  
  80. #ifdef FT_TEST
  81.  
  82.   FUNCTION MAIN(nRow,nCol)
  83.  
  84. * Pass valid row and column values for different video modes to change modes
  85.  
  86.      local nX, nY, cSavClr
  87.      local cSavScr := savescreen( 0, 0, maxrow(), maxcol() )
  88.      local nXm, nYm
  89.      local nSaveRow:=MAXROW()+1, nSaveCol:=MAXCOL()+1
  90.      local nMinor, nType, nIRQ
  91.      local aType:={"Bus","Serial","InPort","PS/2","HP"}
  92.      local nHoriz, nVert, nDouble
  93.      local nTime
  94.  
  95.     IF nRow=NIL
  96.         nRow=MAXROW()+1
  97.     ELSE
  98.         nRow=VAL(nRow)
  99.     ENDIF
  100.  
  101.     IF nCol=NIL
  102.         nCol=MAXCOL()+1
  103.     ELSE
  104.         nCol=VAL(nCol)
  105.     ENDIF
  106.  
  107.     IF .NOT.SETMODE(nRow,nCol)
  108.         @maxrow(),0 SAY "Mode Change unsuccessful:"+STR(nRow,2,0)+" by";
  109.             +STR(nCol,3,0)
  110.         RETURN NIL
  111.     ENDIF
  112.  
  113.      if empty( FT_MINIT() )
  114.         @ maxrow(), 0 say "Mouse driver is not installed!"
  115.         SETMODE(nSaveRow,nSaveCol)
  116.         return ""
  117.      endif
  118.  
  119.      * ..... Set up the screen
  120.      cSavClr := setcolor( "w/n" )
  121.      @ 0,0,maxrow(),maxcol() box "░░░░░░░░░"
  122.  
  123.      setcolor( "GR+/RB" )
  124.      scroll( 7,2,19,63,0 )
  125.      @ 7,2 to 20,63
  126.  
  127.      @ 17, 10 to 19, 40 double
  128.  
  129.      setcolor( "N/W" )
  130.      @ 18, 11 say "  Double Click here to Quit  "
  131.  
  132.      setcolor( "GR+/RB" )
  133.  
  134.      * ..... Start the demo
  135.  
  136.     @MAXROW(),0 SAY "Driver version: "+;
  137.         ALLTRIM(STR(FT_MVERSION(@nMinor,@nType,@nIRQ),2,0))+"."+;
  138.         ALLTRIM(STR(nMinor,2,0))
  139.      @ ROW(),COL() SAY " "+aType[nType]+" mouse using IRQ "+STR(nIRQ,1,0)
  140.  
  141.      FT_MGETSENS(@nHoriz,@nVert,@nDouble)  // Get the current sensitivities
  142.     FT_MSETSENS(70,70,60)    // Bump up the sensitivity of the mouse
  143.  
  144.      FT_MSHOWCRS()
  145.      FT_MSETCOORD(10,20)  // just an arbitrary place for demo
  146.  
  147. * put the unchanging stuff
  148.  
  149.      devpos( 9, 10 )
  150.      devout( "FT_MMICKEYS :" )
  151.  
  152.      devpos( 10, 10 )
  153.      devout( "FT_MGETPOS  :" )
  154.  
  155.      devpos( 11, 10 )
  156.      devout( "FT_MGETX    :" )
  157.    
  158.      devpos( 12, 10 )
  159.      devout( "FT_MGETY    :")
  160.    
  161.      devpos( 13, 10 )
  162.      devout( "FT_MGETCOORD:" )
  163.    
  164.      devpos( 14, 10 )
  165.      devout( "FT_MBUTPRS  :" )
  166.    
  167.      devpos( 16, 10 )
  168.      devout( "FT_MBUTREL  :" )
  169.  
  170.      nX := nY := 1
  171.      do while .t.
  172.  
  173. * If we are not moving then wait for movement.
  174. * This whole demo is a bit artificial in its requirements when compared 
  175. * to a "normal" CLIPPER program so some of these examples are a bit out of
  176. * the ordinary.
  177.    
  178.         DO WHILE nX=0.AND.nY=0 
  179.              FT_MMICKEYS( @nX, @nY )
  180.         ENDDO
  181. * tell the mouse driver where updates will be taking place so it can hide
  182. * the cursor when necessary. 
  183.  
  184.         FT_MCONOFF( 9, 23, 16, 53 )
  185.         nTime=-1
  186.  
  187.         devpos( 9, 23 )
  188.         devout( nX )
  189.         devout( nY )
  190.  
  191.         devpos( 10, 23 )
  192.         DEVOUT( FT_MGETPOS( @nX, @nY ) )
  193.         devout( nX )
  194.         devout( nY )
  195.  
  196.         devpos( 11, 23 )
  197.         DEVOUT(  FT_MGETX() )
  198.  
  199.         devpos( 12, 23 )
  200.         DEVOUT( FT_MGETY() )
  201.  
  202.         devpos( 13, 23 )
  203.         devout( FT_MGETCOORD( @nX, @nY ) )
  204.         devout ( nX )
  205.         devout ( nY )
  206.  
  207.         nX:=nY:=0
  208.         devpos( 14, 23 )
  209.         DEVOUT( FT_MBUTPRS(1) )
  210.         DEVOUT( FT_MBUTPRS(0,, nX, nY) )
  211.         devpos( 15, 23 )
  212.  
  213. * show only the last Press since it flashes by so quickly
  214.  
  215.         IF nX!=0.OR.nY!=0
  216.              devout( nX )
  217.              devout( nY )
  218.         endif
  219.  
  220.         nX:=nY:=0
  221.         devpos( 16, 23 )
  222.         devout( FT_MBUTREL(0,, @nX, @nY) )
  223.  
  224. * show only the last release since it flashes by so quickly
  225.  
  226.         if nX!=0.OR.nY!=0
  227.              devout( nX )
  228.              devout( nY )
  229.         endif
  230.  
  231. * Restore the cursor if it has been hidden
  232.  
  233.         FT_MSHOWCRS()
  234.  
  235.         if FT_MINREGION( 18, 11, 18, 39 )
  236.  
  237. * Change the type of cursor when in the box. Just slightly different than the
  238. * normal. The character is shown in high intensity.
  239.  
  240.            FT_MDEFCRS(0,32767,32512)
  241.            if FT_MDBLCLK(2,0,0.8)  
  242.               exit
  243.            endif
  244.         endif
  245.  
  246.         if FT_MINREGION( 18, 11, 18, 39 )
  247.  
  248. * Change the type of cursor when in the box. Just slightly different than the
  249. * normal. The character is shown in high intensity.
  250.  
  251.            FT_MDEFCRS(0,32767,32512)
  252.         else
  253.  
  254. * Put the cursor back to normal mode
  255.  
  256.            FT_MDEFCRS(0,30719,30464)
  257.         endif
  258.  
  259.         FT_MMICKEYS( @nX, @nY )
  260.      enddo
  261.  
  262.      FT_MHIDECRS()
  263.  
  264.      SETMODE(nSaveRow,nSaveCol)
  265.      setcolor( cSavClr )
  266.      restscreen( 0, 0, maxrow(), maxcol(), cSavScr )
  267.      devpos( maxrow(), 0 )
  268.  
  269. // Reset sensitivity
  270.  
  271.      FT_MSETSENS(nHoriz, nVert, nDouble)
  272.  
  273.   RETURN nil
  274.  
  275.  
  276. #endif 
  277.  
  278.  
  279.  
  280. /*
  281.  * $DOC$         
  282.  * $FUNCNAME$
  283.  *    FT_MINIT()
  284.  * $CATEGORY$
  285.  *    Keyboard/Mouse
  286.  * $ONELINER$
  287.  *    Initialize the mouse driver, vars and return status of mouse
  288.  * $SYNTAX$
  289.  *    FT_MINIT() -> lMouseStatus
  290.  * $ARGUMENTS$
  291.  *    NONE
  292.  * $RETURNS$
  293.  *    An logical representing the mouse status (.F. == mouse not installed)
  294.  * $DESCRIPTION$
  295.  *    Initializes the mouse drive, associated variables and returns mouse 
  296.  *    status. It checks to see if the mouse has been previously initialized
  297.  *    and if so it does not reinitialize. The row and column limits of mouse
  298.  *    movement is set to the maximum for the current video mode. 
  299.  *    Use FT_MSHOWCRS() to display the mouse cursor.
  300.  * $EXAMPLES$
  301.  *    IF .NOT. FT_MINIT()
  302.  *       ? "No mouse driver is installed"
  303.  *    ENDIF
  304.  * $SEEALSO$
  305.  *    FT_MRESET()
  306.  * $END$
  307.  */
  308.  
  309. FUNCTION FT_MINIT()
  310.  
  311. * If not previously initialized th